<?php
    $data = $_APP->_CRUD->readById('* FROM logs WHERE userid!=1 ORDER BY id DESC');
    if($data){
        $ulogs = $data;
        unset($data);
    }

    $data = $_APP->_CRUD->readById('* FROM logs WHERE userid=1 ORDER BY id DESC');
    if($data){
        $alogs = $data;
        unset($data);
    }

    $data = $_APP->_CRUD->readById('* FROM clients');
    if($data){
        $users = $data;
        unset($data);
    }

    $php_logs_file = file(__LOGS__);
?>
<div class="row">
    <div class="twelve columns">
        <div class="box_c">
            <div class="box_c_heading cf box_actions">
                <p>{{Logs}}</p>
            </div>
            <div class="box_c_content">
                <p><a href="javascript:void(0)" class="gh_button small" id="dellogs">{{Purger les logs php}}</a></p>
                <div class="ui_tabs" style="width:98%; margin:0 auto">
                    <ul>
                        <li><a href="#tabs-1">{{Logs Utilisateurs}}</a></li>
                        <li><a href="#tabs-2">{{Logs d'administration}}</a></li>
                        <li><a href="#tabs-3">{{Logs d'erreurs}}</a></li>
                    </ul>
                    <div id="tabs-1">
                        <table class="display" id="data_table_ulogs">
                            <thead>
                                <tr>
                                    <th class="essential">{{Log}}</th>
                                    <th>{{Date}}</th>
                                    <th class="essential">{{Utilisateur}}</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php if(!empty($ulogs)){ ?>
                                    <?php foreach($ulogs as $key => $value){ ?>
                                        <tr>
                                            <td>
                                                <a class="logs" href="readlog.php?id=<?php echo $value['userid']; ?>&log=<?php echo $value['name']; ?>">
                                                    {{Log N°}}<?php echo $value['name']; ?>
                                                </a>
                                            </td>
                                            <td><?php echo $_APP->_USER->sessionToDate($value['name']); ?></td>
                                            <td><?php echo $users[$value['userid']]['name'] . ' ' . $users[$value['userid']]['firstname']; ?></td>
                                        </tr>
                                    <?php } ?>
                                <?php } ?>
                            </tbody>
                        </table>
                    </div>

                    <div id="tabs-2">
                        <table class="display" id="data_table_alogs">
                            <thead>
                                <tr>
                                    <th class="essential">{{Log}}</th>
                                    <th>{{Date}}</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php if(!empty($alogs)){ ?>
                                    <?php foreach($alogs as $key => $value){ ?>
                                        <tr>
                                            <td>
                                                <a class="logs" href="readlog.php?id=<?php echo $value['userid']; ?>&log=<?php echo $value['name']; ?>">
                                                    {{Log N°}}<?php echo $value['name']; ?>
                                                </a>
                                            </td>
                                            <td><?php echo $_APP->_USER->sessionToDate($value['name']); ?></td>
                                        </tr>
                                    <?php } ?>
                                <?php } ?>
                            </tbody>
                        </table>
                    </div>

                    <div id="tabs-3">
                        <?php if(!empty($php_logs_file)){ ?>
                            <?php foreach ($php_logs_file as $line) { ?>
                                <p style="border-bottom:dashed 1px #ddd; margin:15px 0; font-size: 11px; font-family:arial"><?php echo $line; ?></p>
                            <?php } ?>
                        <?php } ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
